<template>
  <div>
    <a-modal width="40%" v-model="visible" title="批量更新" @ok="handleOk">
      <table class="form">
<#list proList as pro>
<#if pro.batchShow&&pro.formType??>
<#if pro.formType=="text"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><div class="w160"><a-input v-model.trim="obj.${pro.name}"></a-input></div></td>
        </tr>
</#if>
<#if pro.formType=="textarea"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><a-textarea v-model="obj.${pro.name}" placeholder="请输入" :rows="4" /></td>
        </tr>
</#if>
<#if pro.formType=="tinymce"> 
        <tr>
          <td class="label w120 top">${pro.column.comment}</td>
          <td class="label w40 top"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><Tinymce :height="400" v-model="obj.${pro.name}"></Tinymce></td>
        </tr>
</#if>
<#if pro.formType=="tags"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><Tags v-model="obj.${pro.name}_arr"></Tags></td>
        </tr>
</#if>
<#if pro.formType=="img"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><UpImg v-model="obj.${pro.name}"></UpImg></td>
        </tr>
</#if>
<#if pro.formType=="imgs"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><UpImgs v-model="obj.${pro.name}_arr"></UpImgs></td>
        </tr>
</#if>
<#if pro.formType=="banner"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><UpBanner v-model="obj.${pro.name}_arr"></UpBanner></td>
        </tr>
</#if>
<#if pro.formType=="int"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><a-input-number v-model="obj.${pro.name}" :min="0" :max="100" :precision="0"/></td>
        </tr>
</#if>
<#if pro.formType=="double"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><a-input-number v-model="obj.${pro.name}" :min="0" :max="100" :precision="2"/></td>
        </tr>
</#if>
<#if pro.formType=="switch"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><a-switch checked-children="开" un-checked-children="关" v-model="obj.${pro.name}"/></td>
        </tr>
</#if>
<#if pro.formType=="date"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><a-date-picker v-model="obj.${pro.name}_mt" format="YYYY-MM-DD"/></td>
        </tr>
</#if>
<#if pro.formType=="time"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><a-time-picker v-model="obj.${pro.name}_mt" format="HH:mm:ss"/></td>
        </tr>
</#if>
<#if pro.formType=="datetime"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td><a-date-picker showTime v-model="obj.${pro.name}_mt" format="YYYY-MM-DD HH:mm:ss"/></td>
        </tr>
</#if>
<#if pro.formType=="select"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td>
            <a-select v-model="obj.${pro.name}" class="w120" :options="dic.${pro.name}Opts"></a-select>
          </td>
        </tr>
</#if>
<#if pro.formType=="checkbox"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td>
            <a-checkbox-group v-model="obj.${pro.name}_optArr" :options="dic.${pro.name}Opts" />
          </td>
        </tr>
</#if>
<#if pro.formType=="radio"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td>
            <a-radio-group v-model="obj.${pro.name}" :options="dic.${pro.name}Opts" />
          </td>
        </tr>
</#if>
<#if pro.formType=="dic"> 
        <tr>
          <td class="label w120">${pro.column.comment}</td>
          <td class="label w40"><a-checkbox v-model="obj.${pro.name}Ck"></a-checkbox></td>
          <td>
            <Dictionary code="${pro.dicCode}" v-model="obj.${pro.name}"></Dictionary>
          </td>
        </tr>
</#if>
</#if>
</#list>
      </table>
    </a-modal>
  </div>
</template>

<script>
import moment from 'moment'
import { dic } from './dic'
export default {
  data () {
    return {
      visible: false,
      dic,
      obj: {},
      ids: []
    }
  },
  mounted () {
    console.log(moment().locale('zh-cn').format('YYYY-MM-DD HH:mm:ss'))
    const idArr = []
    this.init(JSON.stringify(idArr))
  },
  methods: {
    init (ids) {
      this.ids = ids
      this.mode = 1
      this.obj = {
<#list proList as pro>
<#if pro.batchShow&&pro.formType??>
        ${pro.name}Ck: false,
<#if pro.formType=="text"||pro.formType=="textarea"||pro.formType=="img"||pro.formType=="tinymce"||pro.formType=="dic"> 
        ${pro.name}: '',
</#if>
<#if pro.formType=="int"> 
        ${pro.name}: 0,
</#if>
<#if pro.formType=="double"> 
        ${pro.name}: 0.0,
</#if>
<#if pro.formType=="switch"> 
        ${pro.name}: false,
</#if>
<#if pro.formType=="date"> 
        ${pro.name}: '',
        ${pro.name}_mt: moment(),
</#if>
<#if pro.formType=="time"> 
        ${pro.name}: '',
        ${pro.name}_mt: moment(),
</#if>
<#if pro.formType=="datetime"> 
        ${pro.name}: '',
        ${pro.name}_mt: moment(),
</#if>
<#if pro.formType=="banner"||pro.formType=="imgs"||pro.formType=="tags">
        ${pro.name}: '[]',
        ${pro.name}_arr: [],
</#if>
<#if pro.formType=="select">
        ${pro.name}: 1,
</#if>
<#if pro.formType=="radio">
        ${pro.name}: 1,
</#if>
<#if pro.formType=="checkbox">
        ${pro.name}_optArr: [],
</#if>
</#if>
</#list>
        id: '0'
      }
    },
    show () {
      this.visible = true
    },
    hide () {
      this.visible = false
    },
    handleOk () {
<#list proList as pro>
<#if pro.batchShow&&pro.formType??>
<#if pro.formType=="date"> 
      this.obj.${pro.name} = this.obj.${pro.name}_mt.format('YYYY-MM-DD')
</#if>
<#if pro.formType=="time"> 
      this.obj.${pro.name} = this.obj.${pro.name}_mt.format('HH:mm:ss')
</#if>
<#if pro.formType=="datetime"> 
      this.obj.${pro.name} = this.obj.${pro.name}_mt.format('YYYY-MM-DD HH:mm:ss')
</#if>
<#if pro.formType=="banner"||pro.formType=="imgs"||pro.formType=="tags"> 
      this.obj.${pro.name} = JSON.stringify(this.obj.${pro.name}_arr)
</#if>
<#if pro.formType=="checkbox"> 
      this.obj.${pro.name} = JSON.stringify(this.obj.${pro.name}_optArr)
</#if>
</#if>
</#list>
      this.obj.ids = this.ids.join(',')
      this.$http.post('${baseMapping}/batch', this.obj, data => {
        this.hide()
        this.$emit('ok')
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
